//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssProductStockDao;
import com.aidong.model.wills.PssProductStockForTotal;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"purcTotalList"})
public class PurcTotalListController extends BaseController {
    @Resource
    PssProductStockDao pssProductStockDao;

    public PurcTotalListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateFrom = sdf.format(new Date());
        String dateTo = sdf.format(new Date());
        return (new ModelAndView("pss/purcTotalList/list")).addObject("shopName", this.getTypeList("shopName")).addObject("dateFrom", dateFrom).addObject("dateTo", dateTo);
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if(this.chkNull(dateFrom)) {
            dateFrom = sdf.format(new Date());
        }

        if(this.chkNull(dateTo)) {
            dateTo = sdf.format(new Date()) + " 23:59:59";
        }

        dateTo = dateTo + " 23:59:59";
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "a.ShopCode", shopCode);
        this.pssProductStockDao.getProductPssLstByShopCode(pg, cd, dateFrom, dateTo);
        ModelAndView mv = new ModelAndView("pss/purcTotalList/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("productUnit", this.getTypeList("productUnit"));
        mv.addObject("ProductcodeList", this.getTypeList("ProductcodeList"));
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            SimpleDateFormat e = new SimpleDateFormat("yyyy-MM-dd");
            if(this.chkNull(dateFrom)) {
                dateFrom = e.format(new Date());
            }

            if(this.chkNull(dateTo)) {
                dateTo = e.format(new Date()) + " 23:59:59";
            }

            dateTo = dateTo + " 23:59:59";
            Pagination pg = new Pagination(1, 20000);
            pg.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "a.ShopCode", shopCode);
            this.pssProductStockDao.getProductPssLstByShopCode(pg, cd, dateFrom, dateTo);
            ExportXls xls = new ExportXls(response, "商品进销存汇总", "商品进销存汇总");
            xls.addHead(new String[]{"商品编码", "商品名称", "单位", "采购数量（+）", "退货数量（-）", "配送入库数量（+）", "配送出库数量（-）", "销售数量（-）", "报损数量（+-）", "领用数量（-）", "当前库存数量"});
            xls.setWidth(new int[]{10, 25, 10, 10, 10, 10, 10, 10, 10, 10, 10});
            Iterator i$ = pg.getResultList().iterator();

            while(i$.hasNext()) {
                PssProductStockForTotal puot = (PssProductStockForTotal)i$.next();
                xls.addRow(new Object[]{puot.getProductCode(), this.cache.getValue("ProductcodeList", puot.getProductCode()), this.cache.getValue("productUnit", puot.getUnit()), puot.getCgQty1(), puot.getCgQty2(), puot.getPsQty1(), puot.getPsQty2(), puot.getXsQty1(), puot.getBsQty1(), puot.getLyQty1(), puot.getQuantity()});
            }

            xls.close();
            this.addUserLog("导出商品进销存汇总", pg.getResultList().size() + "条记录");
        } catch (Exception var11) {
            this.log.error("import", var11);
        }

        return null;
    }
}
